/**
 * Created by karim on 2017/1/23.
 */

$(function(){
    $("title").text("路由器详情页"); 
	/*获取路由器ID*/
    var location = getUrlParam("sign");
//    window.location.search;
//    location = location.substring(1,999999);
    /*通过ID获取该路由器详细信息*/
        $.ajax({
            url:"tag/findDeviceBox.html",
            type:"post",
            data:{
                id:location,
            },
            success:function(result){
                result=JSON.parse(result);
       		 	if(result.result!=0){
    			 setTimeout(function(){
              		swal(" 查询失败！",result.message, "error");
              	},0);
//    			 alert("查询失败！"+result.message);
    			 return false;
    		 }
                /*判断电源类型*/
                if(result.data[0].supply=="1"){
                	var supply = "电源";
                }else if(result.data[0].supply=="2"){
                	var supply = "适配器";
                }else{
                	var supply = "未获取";
                };
                if(result.data[0].battery==null){
                	var battery = "未获取";
                }else{
                	var battery = result.data[0].battery+"%";
                };
                var routerSn = result.data[0].sn+"";
                var myP = '<table id="routerTable" name="'+result.data[0].id+'" cellspacing="1" cellpadding="0"><tbody cellspacing="1" cellpadding="0" style="padding:0;margin:0;width:100%">'+
				 '<tr><td>编号</td><td class="routerSn">'+routerSn+'</td></tr>'+
				 '<tr><td>备注</td><td>'+result.data[0].title+'</td></tr>'+
				 '<tr><td>电量</td><td>'+battery+'</td></tr>'+
				 '<tr><td>供电方式</td><td>'+supply+'</td></tr>'+
				 '</tbody></table>';
                $("#routerDetailsVal").prepend(myP);
 
            },
            error:function(err){
                console.log(err);
            }
        });
        $("#editSave").click(function(){
        	$("#back").attr("name","2");
        	var roterSn = $(".routerSn").text();
        	window.location.href='setting.html?sign='+roterSn+"_"+location;
        });
        
})